home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / pb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  4.1 KB  |  169 lines

  1. /* $Id: pb.h,v 1.2 1997/02/09 18:43:14 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.2
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: pb.h,v $
  26.  * Revision 1.2  1997/02/09 18:43:14  brianp
  27.  * added GL_EXT_texture3D support
  28.  *
  29.  * Revision 1.1  1996/09/13 01:38:16  brianp
  30.  * Initial revision
  31.  *
  32.  */
  33.  
  34.  
  35. #ifndef PB_H
  36. #define PB_H
  37.  
  38.  
  39. #include "types.h"
  40.  
  41.  
  42.  
  43. /*
  44.  * Pixel buffer size, must be larger than MAX_WIDTH.
  45.  */
  46. #define PB_SIZE (3*MAX_WIDTH)
  47.  
  48.  
  49. struct pixel_buffer {
  50.     GLint x[PB_SIZE];    /* X window coord in [0,MAX_WIDTH) */
  51.     GLint y[PB_SIZE];    /* Y window coord in [0,MAX_HEIGHT) */
  52.     GLdepth z[PB_SIZE];    /* Z window coord in [0,MAX_DEPTH] */
  53.     GLubyte r[PB_SIZE];    /* Red */
  54.     GLubyte g[PB_SIZE];    /* Green */
  55.     GLubyte b[PB_SIZE];    /* Blue */
  56.     GLubyte a[PB_SIZE];    /* Alpha */
  57.     GLuint i[PB_SIZE];    /* Index */
  58.     GLfloat s[PB_SIZE];    /* Texture S coordinate */
  59.     GLfloat t[PB_SIZE];    /* Texture T coordinate */
  60.     GLfloat u[PB_SIZE];    /* Texture R coordinate */
  61.     GLint color[4];        /* Mono color, integers! */
  62.     GLuint index;        /* Mono index */
  63.     GLuint count;        /* Number of pixels in buffer */
  64.     GLboolean mono;        /* Same color or index for all pixels? */
  65.     GLenum primitive;    /* GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP*/
  66. };
  67.  
  68.  
  69. /*
  70.  * Initialize the Pixel Buffer, specifying the type of primitive being drawn.
  71.  */
  72. #define PB_INIT( PB, PRIM )        \
  73.     (PB)->count = 0;        \
  74.     (PB)->mono = GL_FALSE;        \
  75.     (PB)->primitive = (PRIM);
  76.  
  77.  
  78.  
  79. /*
  80.  * Set the color used for all subsequent pixels in the buffer.
  81.  */
  82. #define PB_SET_COLOR( CTX, PB, R, G, B, A )        \
  83.     if ((PB)->color[0]!=(R) || (PB)->color[1]!=(G)    \
  84.      || (PB)->color[2]!=(B) || (PB)->color[3]!=(A)    \
  85.      || !(PB)->mono) {                \
  86.         gl_flush_pb( ctx );            \
  87.     }                        \
  88.     (PB)->color[0] = R;                \
  89.     (PB)->color[1] = G;                \
  90.     (PB)->color[2] = B;                \
  91.     (PB)->color[3] = A;                \
  92.     (PB)->mono = GL_TRUE;
  93.  
  94.  
  95. /*
  96.  * Set the color index used for all subsequent pixels in the buffer.
  97.  */
  98. #define PB_SET_INDEX( CTX, PB, I )        \
  99.     if ((PB)->index!=(I) || !(PB)->mono) {    \
  100.         gl_flush_pb( CTX );        \
  101.     }                    \
  102.     (PB)->index = I;            \
  103.     (PB)->mono = GL_TRUE;
  104.  
  105.  
  106. /*
  107.  * "write" a pixel using current color or index
  108.  */
  109. #define PB_WRITE_PIXEL( PB, X, Y, Z )        \
  110.     (PB)->x[(PB)->count] = X;        \
  111.     (PB)->y[(PB)->count] = Y;        \
  112.     (PB)->z[(PB)->count] = Z;        \
  113.     (PB)->count++;
  114.  
  115.  
  116. /*
  117.  * "write" an RGBA pixel
  118.  */
  119. #define PB_WRITE_RGBA_PIXEL( PB, X, Y, Z, R, G, B, A )    \
  120.     (PB)->x[(PB)->count] = X;            \
  121.     (PB)->y[(PB)->count] = Y;            \
  122.     (PB)->z[(PB)->count] = Z;            \
  123.     (PB)->r[(PB)->count] = R;            \
  124.     (PB)->g[(PB)->count] = G;            \
  125.     (PB)->b[(PB)->count] = B;            \
  126.     (PB)->a[(PB)->count] = A;            \
  127.     (PB)->count++;
  128.  
  129. /*
  130.  * "write" a color-index pixel
  131.  */
  132. #define PB_WRITE_CI_PIXEL( PB, X, Y, Z, I )    \
  133.     (PB)->x[(PB)->count] = X;        \
  134.     (PB)->y[(PB)->count] = Y;        \
  135.     (PB)->z[(PB)->count] = Z;        \
  136.     (PB)->i[(PB)->count] = I;        \
  137.     (PB)->count++;
  138.  
  139.  
  140. /*
  141.  * "write" an RGBA pixel with texture coordinates
  142.  */
  143. #define PB_WRITE_TEX_PIXEL( PB, X, Y, Z, R, G, B, A, S, T, U )    \
  144.     (PB)->x[(PB)->count] = X;                \
  145.     (PB)->y[(PB)->count] = Y;                \
  146.     (PB)->z[(PB)->count] = Z;                \
  147.     (PB)->r[(PB)->count] = R;                \
  148.     (PB)->g[(PB)->count] = G;                \
  149.     (PB)->b[(PB)->count] = B;                \
  150.     (PB)->a[(PB)->count] = A;                \
  151.     (PB)->s[(PB)->count] = S;                \
  152.     (PB)->t[(PB)->count] = T;                \
  153.     (PB)->u[(PB)->count] = U;                \
  154.     (PB)->count++;
  155.  
  156.  
  157. /*
  158.  * Call this function at least every MAX_WIDTH pixels:
  159.  */
  160. #define PB_CHECK_FLUSH( CTX, PB )        \
  161.     if ((PB)->count>=PB_SIZE-MAX_WIDTH) {    \
  162.        gl_flush_pb( CTX );            \
  163.     }
  164.  
  165.  
  166. extern void gl_flush_pb( GLcontext *ctx );
  167.  
  168. #endif
  169.